//
//  UIImage+Extension.swift
//  CLWeiNo
//
//  Created by DDC on 2017/10/14.
//  Copyright © 2017年 DDC. All rights reserved.
//

import Foundation

extension UIImage {
    
    func cll_avatarImage(image:UIImage , size:CGSize , backColor:UIColor?)->UIImage? {
        
        let rect = CGRect(origin: CGPoint(), size: size)
        
        // 开启图片上下文
        UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
        
        // 背景填充
        backColor?.setFill()
        UIRectFill(rect)
        
        // 圆形描绘
        let path = UIBezierPath(ovalIn: rect)
        path.addClip()
        
        // 开始绘图
        image.draw(in: rect)
        
        // 圆形描边
        UIColor.darkGray.setStroke()
        
        // 设置线宽
        path.lineWidth = 2
        
        // 绘制描边
        path.stroke()
        
        // 绘制图片
        let result = UIGraphicsGetImageFromCurrentImageContext()
        
        // 关闭上下文
        UIGraphicsEndImageContext()

        return result


        
    }
    
    
    
}
